(function($) {
        //预约挂号
     $.getMyorderUrl={
        getpageUrl:function(urlName){
	        var yygh ={
	            //取消预约
	             cancelReservation:'yygh/cancelReservation',
	            //一级科室列表查询
	             getDeptListTop:'yygh/getDeptListTop',
	            //二级科室列表查询
	            getDeptListTwo:'yygh/getDeptListTwo',
	            //获取医生详情
	             getDoctorDetail:'yygh/getDoctorDetail',
	            //医生列表查询
	            getDoctorList:'yygh/getDoctorList',
	            //查询医院列表
	            getHospitalList:'yygh/getHospitalList',
	            //获取就诊人信息
	            getJzrInfo:'yygh/getJzrInfo',
	            //号源查询
	             getNumSource:'yygh/getNumSource',
	            //号源查询(按专家)
	             getNumSourceByYs:'yygh/getNumSourceByYs',
	            //预约单详情查询
	             getOrderDetail:'yygh/getOrderDetail',
	            //预约单列表
	             getOrderRecords:'yygh/getOrderRecords',
	            //号源预约
	             submitOrderByUserInfo:'yygh/submitOrderByUserInfo',
                 //医院(门诊)信息查询
                getResource:"yygh/getResource",
                //根据就诊人id查询就诊卡列表
                queryJzkList:"jzk/queryList",


	        };

	       return "/api/gzd/"+yygh[urlName]
  	  }
  	}
  
})(jQuery);
function yyghSetControl(){

 $(".pay-btn").attr("urlInfo",JSON.stringify({successUrl:$.getUrl.pageUrl("myOrder","wdyy")+"?backToIndex=yes",closeUrl:$.getUrl.pageUrl("myOrder","wdyy")}));
    $(".pay-btn").click(function(){
        var ysinfo = JSON.parse(localStorage.YYGH_YSINFO);
        var hyInfo = StoreCache.getCache("YYGH_HYINFO");
        var parmas={
            "yljgdm":ysinfo.hosCode,
            "order_id":$("#jzr").data("orderId"),
            "schedule_id":$("#jzr").data("scheduleId"),
            "je":hyInfo.visitCost,
            "klx":"01",
            "kh":$("#jzr").data("info").sfzh
         }
        toGetPay(parmas);
    })

 /**选择就诊人*/
       /* $(".arrow-right,#jzr").on("click", function () {
            $.pageSwitch.goToUrl("common","selectePerson")
        });*/
//确认预约start
        $(".qd-btn").on("click",function(){
                var jzrInfo = $("#jzr").data("info");
                if(jzrInfo){
                   //StoreCache.setCache("YYGH_MEDICARD", mediCard);
                   //根据就诊人信息查询就诊卡列表
                    $.QuickRemote.AjaxJson({
                    funcName:$.getMyorderUrl.getpageUrl("queryJzkList")
                    ,callback:function (result) {
                        /**解析二级科室*/
                        var data = result;
                        if(data && data.length>0){
                            var mrJzkFlag = false;
                            var mrJzkInfo = "";
                            $(data).each(function (index, item) {
                                if(item["sfmr"] == "1"){
                                    mrJzkInfo = item;
                                    mrJzkFlag = true;
                                    
                                }
                            });
                            if(mrJzkFlag){
                                /**号源预约*/
                                var hyInfo = StoreCache.getCache("YYGH_HYINFO");
                                var hosInfo = StoreCache.getCache("YYGH_HOSINFO");
                                var params = {};
                                params["hosCode"] = hyInfo["hosCode"];
                                params["depCode"] = hyInfo["depCode"];
                                params["hosName"] = hosInfo?hosInfo["hosName"]:hyInfo["hosName"];
                                params["docCode"] = hyInfo["docCode"];
                                params["doctName"] = hyInfo["docName"];
                                params["oneDepCode"] = hyInfo["oneDepCode"];
                               // params["regType"] = hyInfo["regType"];
                                params["numSourceCode"] = hyInfo["numSourceCode"];
                                params["scheduleCode"] = hyInfo["scheduleCode"];
                                params["payMode"] = "3";
                                params["mediCardId"] = mrJzkInfo["jzkh"];
                                params["mediCardType"] = mrJzkInfo["jzklx"];


                                /*
                                params["visitCost"] = hyInfo["visitCost"];
                                params["payState"]="2",
                                params["password"] = "123456";*/

                                params["patientCardType"] = "1";
                                params["patientCardId"] =jzrInfo["sfzh"];
                                
                                params["patientPhone"] = jzrInfo["sj"];
                               // params["patientName"] = jzrInfo["name"];
                                params["patientName"] = jzrInfo["xm"];
                                params["patientGender"] = jzrInfo["xb"];
                                params["orderType"] = hyInfo["orderType"];

                                date = new Date(jzrInfo["csrq"].replace(/(\d{4})(\d{2})(\d{2})/g,'$1-$2-$3'));                                 
                                params["birthday"] = date.Format("yyyy-MM-dd");
                                
                               //  params["orderType"]="1";
                                 /*params["orderTime"]=hyInfo["scheduleDate"];
                                 params["timeRange"] = hyInfo["timeRange"];
                                 params["visitLevel"] = hyInfo["regType"];
                                 params["deptName"] = hyInfo["depName"];*/
                                saveYyghInfo(params);

                            }else{
                                 $.QuickAlert.alertFail({
                                     content : "请设置默认就诊卡！"
                                 });                               
                            }

                        }else{
                            $.QuickAlert.alertFail({
                                 content : "请添加就诊卡并设置默认就诊卡！"
                             });
                        }

                    }
                    ,params:{jmjbxxid: jzrInfo["jmjbxxid"]}
                });


            }else{
                    $.QuickAlert.alertFail({
                        content : "请设置自己为默认就诊人！"
                    });
                }

        });
 

    function saveYyghInfo(params){
        $.QuickRemote.AjaxJson({
            funcName:$.getMyorderUrl.getpageUrl("submitOrderByUserInfo")
            ,callback:function(result) {
                   // $('.pay-list-box').show();
                   // $("#jzr").data("scheduleId",result.scheduleCode);
                   // $("#jzr").data("orderId",result.yydbh);
                /*预约成功跳转到详情页*/
              //  StoreCache.setCache("YYGH_YYCGINFO",result);
                 $.pageSwitch.goToUrl("myOrder","yyDetail","orderId="+result.orderId+"&hosCode="+result.hosOrgCode);
                 ///yyDetailWithoutPay

            },params:params
        });
        
    }
    /**获取就诊人信息*/
        var params = {};
        var info = StoreCache.getCache("searchInfo");
        info= info && info.userInfo ?JSON.parse(info.userInfo):"";
        if(info!=""){

            var name = info["xm"];
            if(!StringUtils.isEmpty(name)){
                $("#jzr").text(name);
            }
            $("#jzr").data("info", info);
        }else
            $.QuickRemote.AjaxJson("/api/gzd/yygh/getJzrInfo", function(data) {
                    var name = data["xm"];
                    if(!StringUtils.isEmpty(name)){
                        $("#jzr").text(name);
                    }
                    $("#jzr").data("info", data);
            });
//确认预约end
}